package kr.hkit.androidcomplete02.ch17;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class CommActivity extends Activity {
	TextView tv;
	final static int REQ_CODE = 0;
	final static int CAL_REQ_CODE = 1;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch17_commactivity);
		
		tv = (TextView) findViewById(R.id.ch17_commactivity_tv);
	}
	
	public void mOnClick(View v){
		if(v.getId() == R.id.ch17_commactivity_btn){
			Intent intent = new Intent(this, ActEdit.class);
			intent.putExtra("textIn", tv.getText().toString());
			startActivityForResult(intent, REQ_CODE);
		}
		
		if(v.getId() == R.id.ch17_commactivity_btn2){
			Intent intent = new Intent(this, CalAct.class);
			intent.putExtra("leftValue", 3);
			intent.putExtra("rightValue", 4);
			startActivityForResult(intent, CAL_REQ_CODE);
			
		}
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch(requestCode){
		case REQ_CODE:
			if(resultCode == RESULT_OK){
				tv.setText(data.getStringExtra("textOut"));
			}else{
				tv.setText("Cancel");
			}
			break;
		case CAL_REQ_CODE:
			if(resultCode == RESULT_OK){
				tv.setText(data.getStringExtra("Result"));
			}
			break;
		}
	}
}
